local jingong = fk.CreateSkill{
  name = "wk_heg__jingong",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["wk_heg__jingong"] = "矜功",
  [":wk_heg__jingong"] = "锁定技，结束阶段，若本回合受到你造成伤害的角色数：为1，你摸两张牌；大于1，你失去1点体力。",
  
  ["$wk_heg__jingong1"] = "董贼旧部，可尽诛之！",
  ["$wk_heg__jingong2"] = "若无老夫之谋，尔等皆化为腐土也。",
}

jingong:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if not (player:hasSkill(self) and player.phase == Player.Finish) then return false end
    local damaged = {}
    local events = player.room.logic:getActualDamageEvents(99, function(e)
      if e.data.from and e.data.from == player and e.data.to then
        table.insertIfNeed(damaged, e.data.to)
        return true
      end
      return false
    end, Player.HistoryTurn)
    if #events > 0 then
      event:setCostData(self, {damaged = damaged})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(jingong.name)
    local num = #event:getCostData(self).damaged
    if num == 1 then
      room:notifySkillInvoked(player, jingong.name, "drawcard")
      player:drawCards(2, jingong.name)
    else
      room:notifySkillInvoked(player, jingong.name, "negative")
      room:loseHp(player, 1, jingong.name)
    end
  end,
})

return jingong